package com.csxy.six.controller;

import com.csxy.six.R;
import com.csxy.six.entity.GoodsReport;
import com.csxy.six.service.GoodsReportService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Tag(name = "goods-reports", description = "商品举报管理")
@RestController
@RequestMapping("/market/reports")
public class GoodsReportController {

    @Autowired
    private GoodsReportService goodsReportService;

    @Operation(summary = "举报商品", description = "提交商品举报信息")
    @PostMapping("/save")
    public R reportGoods(@RequestBody GoodsReport report) {
        boolean flag = goodsReportService.getBaseMapper().insert(report) > 0;
        if (flag) {
            return R.ok();
        }
        return R.error();
    }

    @Operation(summary = "获取待处理的举报信息", description = "查询所有状态为待处理的商品举报信息")
    @GetMapping("/pending")
    public R getPendingReports() {
        List<GoodsReport> list = goodsReportService.getPendingReports();
        return R.ok().data("items", list);
    }

    @Operation(summary = "更新举报信息状态", description = "根据举报信息ID更新其状态")
    @PostMapping("/update")
    public R updateReportStatus(@RequestBody GoodsReport report) {
        boolean flag = goodsReportService.updateById(report);
        if (flag) {
            return R.ok();
        }
        return R.error();
    }

    @Operation(summary = "删除举报信息", description = "根据ID删除举报信息")
    @DeleteMapping("/remove/{id}")
    public R removeReport(@PathVariable Integer id) {
        boolean flag = goodsReportService.removeById(id);
        if (flag) {
            return R.ok();
        }
        return R.error();
    }
}
